<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    
    
  </table>
    <script>
      let sales = [
        { name: '小明', age: 18, gender: '男', money: 30, status: 0 },
        { name: '小红', age: 26, gender: '女', money: 99, status: 3 },
        { name: '小刚', age: 19, gender: '男', money: 88, status: 2 },
        { name: '小丽', age: 20, gender: '女', money: 67, status: 1 },
        { name: '晓强', age: 23, gender: '女', money: 77, status: 1 },
        { name: '小张', age: 25, gender: '女', money: 80, status: 2 },
      ]
      function change(arr){
        let html=`<table>
      <tr>
        <th>名次</th>
        <th>姓名</th>
        <th>年纪</th>
        <th>性别</th>
        <th>销售额</th>
        <th>业绩状态</th>
      </tr>`
      // 建立营业额排序后的数组
      let sort=[]
      for(let a in arr){
        sort.push(arr[a].money)
      }
      sort.sort(function(a,b){
      return b-a
    })
    // 根据数组从大到小依次遍历
    for(let i =0;i<sort.length;i++){
      for(let a in arr){
        if(sort[i]===arr[a].money){
          let str
          switch (arr[a].status) {
            case 0:
              str='未及格'
              break;
            case 1:
              str='及格'
              break;
            case 2:
              str='良好'
              break;
            case 3:
              str='优秀'
              break;
            default:
              break;
          }
          html+=`<tr>
      <td>${i+1}</td>
      <td>${arr[a].name}</td>
      <td>${arr[a].age}</td>
      <td>${arr[a].gender}</td>
      <td>${sort[i]+'w'}</td>
      <td>${str}</td>
    </tr>`
        }
      }
    }
        document.write(html);
      }
      change(sales)
    </script>
  </body>
</html>
